﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 下发到PLC的记录
    /// </summary>
    public partial class PlcAssign : BusEntity
    {
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 下发类型
        /// </summary>
        public string Type { get; set; }
        /// <summary>
        /// 分组
        /// 同一组要一起下发
        /// </summary>
        public string Group { get; set; }
        /// <summary>
        /// 下发顺序(排序)/分组
        /// </summary>
        public int Seq { get; set; }
        /// <summary>
        /// PLC IP地址
        /// </summary>
        public string PlcIp { get; set; }
        /// <summary>
        /// 逻辑地址
        /// </summary>
        public string LogAddr { get; set; }
        /// <summary>
        /// 下发的值
        /// </summary>
        public string Value { get; set; }
        /// <summary>
        /// 引自哪个数据表
        /// </summary>
        public string RefTable { get; set; }
        /// <summary>
        /// 引自哪个Id
        /// </summary>
        public string RefId { get; set; }
        /// <summary>
        /// 下发状态
        /// </summary>
        public string Status { get; set; }
        /// <summary>
        /// 下发时间
        /// </summary>
        public DateTime AssignTime { get; set; }
        /// <summary>
        /// 下发失败次数
        /// </summary>
        public int FailCount { get; set; }
        /// <summary>
        /// 下发备注消息
        /// </summary>
        public string Msg { get; set; }
    }

    public partial class PlcAssign : BusEntity
    {
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class PLCAssignTypeConfig : BusEntityTypeConfig<PlcAssign>, IEntityTypeConfiguration<PlcAssign>
    {
        public override void Configure(EntityTypeBuilder<PlcAssign> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Type).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Group).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.Seq).IsRequired();
            builder.Property(p => p.PlcIp).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.LogAddr).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Value).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.RefTable).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.RefId).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.Status).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.AssignTime);
            builder.Property(p => p.FailCount).HasDefaultValue(0).IsRequired();
            builder.Property(p => p.Msg).HasMaxLength(EntityDefinition.DefLargeColLen).IsRequired(false);
            #endregion

            #region 备注
            builder.HasComment("下发到PLC的记录");
            builder.Property(p => p.Name).HasComment("名称");
            builder.Property(p => p.Type).HasComment("下发类型");
            builder.Property(p => p.Group).HasComment("分组");
            builder.Property(p => p.Seq).HasComment("下发顺序");
            builder.Property(p => p.PlcIp).HasComment("PLC IP地址");
            builder.Property(p => p.LogAddr).HasComment("逻辑地址");
            builder.Property(p => p.Value).HasComment("下发的值");
            builder.Property(p => p.RefTable).HasComment("引自哪个数据表");
            builder.Property(p => p.RefId).HasComment("引自哪个Id");
            builder.Property(p => p.Status).HasComment("下发状态");
            builder.Property(p => p.AssignTime).HasComment("下发时间");
            builder.Property(p => p.FailCount).HasComment("下发失败次数");
            builder.Property(p => p.Msg).HasComment("下发备注消息");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
